//@ts-ignore
import request from "@/utils/request.ts";

//引入类型
import { trademarkListData, responseTrademarkListData, saveTrademarkData, responseSaveTrademarkData, responseDeleteTrademarkData
    ,responseProductCategoryData, responseProductAttrValue, productAttrObj } from "./type.ts";

enum API {
    //品牌管理
    TRADEMARKDATA_URL = "/admin/product/baseTrademark",
    TRADEMARKSAVE_URL = "/admin/product/baseTrademark/save",
    TRADEMARKUPDATE_URL = "/admin/product/baseTrademark/update",
    TRADEMARKREMOVE_URL = "/admin/product/baseTrademark/remove",
    //平台属性管理
    PRODUCTCATEGORY1 = "/admin/product/getCategory1",
    PRODUCTCATEGORY2 = "/admin/product/getCategory2",
    PRODUCTCATEGORY3 = "/admin/product/getCategory3",
    PRODUCTATTRLIST = "/admin/product/attrInfoList",
    PRODUCTSAVEATTRVALUE = "/admin/product/saveAttrInfo",
    DELETEPRODUCTATTR = "/admin/product/deleteAttr",
    //SPU管理接口
    PRODUCTHASSPU_URL="/admin/product",  //获取已有的spu数据
    ALLTRADEMARK_URL="/admin/product/baseTrademark/getTrademarkList",  //获取所有品牌数据
    IMAGE_URL="/admin/product/spuImageList",  //获取某spu下的全部的售卖商品的图片数据
    SPUHASSALLATTR="/admin/product/spuSaleAttrList",  //获取某个SPU下全部已有的销售属性
    ALLSALEATTR_URL="/admin/product/baseSaleAttrList",  //获取整个项目全部的销售属性[颜色，版本，尺码]
    ADDSPU_URL = "/admin/product/saveSpuInfo",  //添加一个spu
    UPDATESPU_URL = "/admin/product/updateSpuInfo",  //更新一个spu
    DELETESPU_URL = "/admin/product/deleteSpu",  //删除一个spu
    ADDSKU_URL="/admin/product/saveSkuInfo",  //添加一个sku
    SKUINFO_URL = "/admin/product/findBySpuId",  //查看一个spu下的sku
}
/**
 * 品牌管理部分接口
 */
//获取品牌基本数据接口
export const reqTrademarkList = (data:trademarkListData) => {
    return request<any,responseTrademarkListData>({
        url:API.TRADEMARKDATA_URL + "/" + data.page + "/" + data.limit,
        method:"get"
    })
}

//新增一个品牌接口
export const reqSaveTrademark = (trademark:saveTrademarkData) => {
    return request<any,responseSaveTrademarkData>({
        url:API.TRADEMARKSAVE_URL,
        method:"post",
        data:trademark
    })
}

//更新一个品牌数据接口
export const reqPutTrademark = (trademark:saveTrademarkData) => {
    return request<any,responseSaveTrademarkData>({
        url:API.TRADEMARKUPDATE_URL,
        method:"put",
        data:trademark
    })
}

//删除一个品牌接口
export const reqRemoveTrademark = (id:number) => {
    return request<any,responseDeleteTrademarkData>({
        url:API.TRADEMARKREMOVE_URL + '/' + id,
        method:"delete"
    })
}

/**
 * 平台属性部分接口
*/
//获取商品一级分类
export const reqProductCategory1 = () => {
    return request<any,responseProductCategoryData>({
        url:API.PRODUCTCATEGORY1,
        method:"get"
    })
}
//获取商品二级分类
export const reqProductCategory2 = (category1Id:number) => {
    return request<any,responseProductCategoryData>({
        url:API.PRODUCTCATEGORY2 +"/"+ category1Id,
        method:"get"
    })
}
//获取商品三级分类
export const reqProductCategory3 = (category2Id:number) => {
    return request<any,responseProductCategoryData>({
        url:API.PRODUCTCATEGORY3 +"/"+ category2Id,
        method:"get"
    })
}

//获取商品基础属性
export const reqProductAttrList = (category1Id:number,category2Id:number,category3Id:number) => {
    return request<any,responseProductAttrValue>({
        url:API.PRODUCTATTRLIST +"/"+ category1Id +"/"+ category2Id +"/"+ category3Id,
        method:"get"
    })
}
//新增商品基础属性
export const reqSaveProductAttr = (attrValueObj:productAttrObj) => {
    return request<any,any>({
        url:API.PRODUCTSAVEATTRVALUE,
        method:"post",
        data:attrValueObj
    })
}
//删除一条商品基础属性
export const reqDeleteProductAttr = (attrId:number) => {
    return request<any,any>({
        url:API.DELETEPRODUCTATTR +'/'+ attrId,
        method:"delete"
    })
}

/**
 * SPU管理模块接口
*/
//@ts-ignore,此处引入类型
import { HasSpuResponseData, AlltradeMark, SpuHasImg, SaleAttrResponseData, hasSaleAttrResponseData, spuDataParams, skuParams, skuInfoData } from "./type.ts";

//获取某一个三级分类下的spu数据
export const reqProductSpu = (page:number,limit:number,category3Id:string|number) => {
    return request<any,HasSpuResponseData>({
        url:API.PRODUCTHASSPU_URL +"/"+ page +"/"+ limit +"?category3Id="+ category3Id,
        method:"get"
    })
}

//获取全部spu的品牌数据
export const reqAllTrademark = () => {
    return request.get<any,AlltradeMark>(API.ALLTRADEMARK_URL);
}

//获取某spu下的全部商品图片
export const reqSpuImageList = (spuId:number) => {
    return request<any,SpuHasImg>({
        url:API.IMAGE_URL +"/"+ spuId,
        method:"get"
    })
}

//获取某一个已有spu拥有多少个销售属性
export const reqSpuHasSaleAttr = (spuId:number) => {
    return request<any,SaleAttrResponseData>({
        url:API.SPUHASSALLATTR +"/"+ spuId,
        method:"get"
    })
}

//获取全部的销售属性
export const reqAllSaleAttr = () => {
    return request<any,hasSaleAttrResponseData>({
        url:API.ALLSALEATTR_URL,
        method:"get"
    })
}

//添加一个新的spu
export const reqAddSpu = (spuInfo:spuDataParams) => {
    return request<any,any>({
        url:API.ADDSPU_URL,
        method:"post",
        data:spuInfo
    })
}

//更新一个spu
export const reqUpdateSpu = (spuInfo:spuDataParams) => {
    return request<any,any>({
        url:API.UPDATESPU_URL,
        method:"post",
        data:spuInfo
    })
}

/**
 * sku管理模块
*/
//1.获取平台属性接口(工具一二三级id,上面有)
//2.获取spu已有图片接口(spu.id)
//3.获取spu已有销售属性接口(spu.id)

//添加一个新的sku
export const reqAddSku = (skuInfo:skuParams) => {
    return request<any,any>({
        url:API.ADDSKU_URL,
        method:"post",
        data:skuInfo
    })
}

//查询一个spu下的sku
export const reqSkuInfo = (spuId:number) => {
    return request<any,skuInfoData>({
        url:API.SKUINFO_URL +"/"+ spuId,
        method:"get"
    })
}


//删除一个spu
export const reqDeleteSpu = (spuId:number) => {
    return request<any,any>({
        url:API.DELETESPU_URL +"/"+ spuId,
        method:"delete"
    })
}


/**
 * SKU管理模块
*/

//查询所有sku数据
export const reqAllSku = (page:number,limit:number) => {
    return request<any,any>({
        url:"/admin/product/list" +"/"+ page +"/"+ limit,
        method:"get"
    })
}
//sku商品上架
export const reqOnSale = (skuId:number) => {
    return request<any,any>({
        url:"/admin/product/onSale" +"/"+ skuId,
        method:"get"
    })
}
//sku商品下架
export const reqCancelSale = (skuId:number) => {
    return request<any,any>({
        url:"/admin/product/cancelSale" +"/"+ skuId,
        method:"get"
    })
}
//sku商品的详情
export const reqSkuInfoList = (skuId:number) => {
    return request<any,any>({
        url:"/admin/product/getSkuInfo" +"/"+ skuId,
        method:"get"
    })
}
//删除一个sku
export const reqDeleteSku = (skuId:number) => {
    return request<any,any>({
        url:"/admin/product/deleteSku" +"/"+ skuId,
        method:"delete"
    })
}
